//od机试.中等.字符串迷宫寻找字符串/不能bfs/std::vector<bool>中的坑
// 测试输入
// 2 4
// solo
// aolf
// esol
// 输出 YES

#include <bits/stdc++.h>
using namespace std;

bool dfsFind(const vector<string>& vtMaze, string sTarget, vector<vector<int>>& vtVisit, int px, int py) {
    if(sTarget.length() == 1) {
        return vtMaze[px][py] == sTarget[0];
    }
    vtVisit[px][py] = 1;
    vector<pair<int,int>> dirs = {{0,1}, {0,-1}, {1,0}, {-1,0}};
    bool result = false;
    for(auto [dx,dy] : dirs) {
        size_t cx = px + dx, cy = py + dy;
        if ( cx < 0 || cx >= vtMaze.size()
             || cy < 0 || cy >= vtMaze[0].size()) {
            continue;
        }
        if (sTarget[1] == vtMaze[cx][cy] && !vtVisit[cx][cy]) {
            bool ret = dfsFind(vtMaze, sTarget.substr(1), vtVisit, cx, cy);
            if (!ret) {
                vtVisit[cx][cy] = 0;
            }
            result |= ret;
        }
    }
    return result;
}

string word_maze(const vector<string>& vtMaze, const string& sTarget) {
    for (size_t i =0; i<vtMaze.size(); i++) {
        for (size_t j=0; j<vtMaze[0].length(); j++) {
            if (vtMaze[i][j] == sTarget[0]) {
                vector<vector<int>> vtVis(vtMaze.size(), vector<int>(vtMaze[0].size(), 0));
                if (dfsFind(vtMaze, sTarget, vtVis, i, j)) {
                    return "YES";
                }
            }
        }
    }
    return "NO";
}

int main_word() {
    int r,c;
    while(cin >> r >> c) {
        string tmp,sTarget;
        vector<string> vtMaze;
        cin >> sTarget;
        while(r-->0) {
            cin >> tmp;
            vtMaze.push_back(tmp);
        }
        cout << word_maze(vtMaze, sTarget) << endl;
    }
}
